using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;

/**
*@file       DBRole_Enter_SuccessReciever.cs
*@brief      process message DBRole_Enter_Success
*
*@author     graywind
*@version    1.0.0.1
*@data       2012/3/26
*/

//process DBRole_Enter_Success
public class OnDBRole_Enter_Success
{
    /// <summary>
    /// process message
    /// </summary>
    /// <param name="op">message operator</param>
    /// <param name="session_id">session identifier</param>
    /// <param name="msg_buffer">message buffer</param>
    /// <param name="msg_bytes">buffer length</param>
    public static void OnMapping(IMessageOperator op, Int32 session_id, byte[] msg_buffer, UInt32 msg_bytes)
    {
        //TODO
		dbserver.DBRoleEnterSuccess db_role_enter = ProtoNet<dbserver.DBRoleEnterSuccess>.CreateFromBytes(msg_buffer, msg_bytes);

        GameWorld game_world = op.WorldManager.Get(db_role_enter.RoleInfo.WorldId);
        if (game_world != null)
        {
            WorldObject.PlayerObject player_obj = GameWorld.CreatePlayerObject(db_role_enter.RoleInfo, db_role_enter.GateCode);
            if (game_world.Add(player_obj))
            {
				msgGCRoleInfo enter_success = new msgGCRoleInfo(op.GatewayConnHandle, db_role_enter.GateCode, db_role_enter.RoleInfo);
				gwMessagePort.ProcessMessage(enter_success);
            }
            else
            {
				msgGSRole_Enter_Failed failed = new msgGSRole_Enter_Failed(op.GatewayConnHandle, db_role_enter.GateCode,gatewayserver.EnterFailed.eErrorCode.Usr_Alreay_Online);
				gwMessagePort.ProcessMessage(failed);
            }
        }
        else
            System.Console.WriteLine("World Not Exists! Maybe Delete Somewhere!!!");
    }
}

//register callback
partial class MessageProcTypes<ProcType, MessageProc>
{
        [MessageProcType((int)DBServerTypes.MessageType.DBRole_Enter_Success)]
        public static DBServerProcessor.DBServerTabFunc DBRole_Enter_SuccessProc = new DBServerProcessor.DBServerTabFunc(OnDBRole_Enter_Success.OnMapping);
}
